package GUI;

/**
 * For the exceptional request of student removal during the semester , 
 * the administration selects from which course the selected student wants to be removed
 */

import java.awt.Dimension;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class StudentRemovalFromCourse extends JPanel {

	private JLabel lblExceptionalRequest = null;
	private JLabel lblSelectCourse = null;
	private JComboBox cBSelCourse = null;
	public Login myLoginFrame = null;
	public UserAdmin user=null;
	public AdminMainMenu amn=null;
	private JButton btnRequestAuthorization = null;
	
	
	
	
	
	
	private JComboBox getcBSelCourse(AdminMainMenu amm)
	{
	
		System.out.println("Test1 "+amm.user.DataForEx.StudentsWithCourses.size());
			
		Vector<String> data  = new Vector<String>();
		
	for(int i=0;i<amm.user.DataForEx.StudentsWithCourses.size();i++)
	{
		System.out.println("GetNAme+ " +amm.user.GetName());
		System.out.println("GetNAme1+ " +amm.user.DataForEx.StudentsWithCourses.get(i).Sid);
		if(amm.user.GetName().endsWith(amm.user.DataForEx.StudentsWithCourses.get(i).Sid.toString()))
		{	
			System.out.println("GetSize+ " +amm.user.DataForEx.StudentsWithCourses.get(i).ListOfCourses.lOfCourses.size());
		for(int j=0;j<amm.user.DataForEx.StudentsWithCourses.get(i).ListOfCourses.lOfCourses.size();j++)
		{
			
			
		
		data.add(amm.user.DataForEx.StudentsWithCourses.get(i).ListOfCourses.lOfCourses.get(j).getCname() +" "+amm.user.DataForEx.StudentsWithCourses.get(i).ListOfCourses.lOfCourses.get(j).getCid());
		}
		}
		
	}
		
		
		if(cBSelCourse==null)
		{
			cBSelCourse = new JComboBox(data);
			cBSelCourse.setBounds(99, 188, 155, 20);
			
		}
		
		return cBSelCourse;
	}
	
	
	
	private JButton getbtnRequestAuthorization()
	{
		if(btnRequestAuthorization==null)
		{
			btnRequestAuthorization = new JButton("Request authorization");
			btnRequestAuthorization.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					String[] selsectedCourse=cBSelCourse.getSelectedItem().toString().split(" ");//[1] - cid
					//System.out.println("The selected course is: "+ selsectedCourse[1]);
					String[] selectedStud=amn.user.GetName().toString().split(" ");
					amn.user.DataForEx.RequestCreated=false;
					amn.myLoginFrame.client.handleMessageFromClientUI("CreateExReqRemoveStudFromCourse "+selsectedCourse[1]+" "+selectedStud[selectedStud.length-1]);
					while(!amn.user.DataForEx.RequestCreated);
					//TODO Send the request to the principle for authorization
				}
			});
			btnRequestAuthorization.setBounds(342, 268, 139, 23);
			
		}
		
		return btnRequestAuthorization;
	}
	
	private void initialize(AdminMainMenu amm)
	{
		setLayout(null);
		setSize(getMaximumSize());
		
		 lblExceptionalRequest = new JLabel("Exceptional request - Remove student from course");
		lblExceptionalRequest.setBounds(131, 11, 244, 14);
		
		
		 lblSelectCourse = new JLabel("Select course:");
		lblSelectCourse.setBounds(10, 191, 68, 14);
		
		this.add(lblSelectCourse);
		this.add(lblExceptionalRequest);
		this.add(getcBSelCourse(amm));
		this.add(getbtnRequestAuthorization());
	}
	
	
	
	
	
	
	public StudentRemovalFromCourse(AdminMainMenu amm) {
		super();
		initialize(amm);
		
	}
}
